/*
https://leetcode.cn/problems/self-dividing-numbers/description/
*/

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int div_self(int x) {
    if (x == 0)
        return 0;
    int num = x;
    while (x) {
        int bit = x % 10;
        if (bit == 0)
            return 0;
        if (num % bit != 0)
            return 0;
        x /= 10;
    }
    return 1;
}
int* selfDividingNumbers(int left, int right, int* returnSize) {
    int* returnnums = (int*)malloc(sizeof(int)*(right - left + 1));
    int pos = 0;
    for (int i = left; i <= right; i++) {
        if (div_self(i))
            returnnums[pos++] = i;
    }
    *returnSize = pos;
    return returnnums;
}